package com.itheima.noDieRabbit;

import java.util.ArrayList;

/*
已知：有一对兔子，从出生后第3个月起每个月都生一对兔子，小兔子长到第三个
	月后每个月又生一对兔子，假如兔子都不死，问第二十个月的兔子对数为多少？
	请用递归思想实现代码。
 */
public class neverDieRabbit {
    static int sum = 1;
    static int WEEK = 20;
    public static void main(String[] args) {
        int month = 0;
        ArrayList<Integer> oRabbit = new ArrayList<>();
        ArrayList<Integer> newRabbit = new ArrayList<>();
        getNum(month,oRabbit,newRabbit);
    }

    private static void getNum(int month, ArrayList<Integer> oRabbit, ArrayList<Integer> newRabbit) {
        if (month<3-1){
            oRabbit.add(1);
            newRabbit.add(0);
        }else {
            oRabbit.add((oRabbit.get(month - 1)) + newRabbit.get(month - 2));
            newRabbit.add(oRabbit.get(month));
        }
        sum += newRabbit.get(month);
        System.out.println("老兔子：" + oRabbit.get(month) + "，新生兔：" + newRabbit.get(month) + ",总和:" + sum + "，月份：" + (month+1));
        if (month < WEEK-1){
            month++;
            getNum(month,oRabbit,newRabbit);
        }else {
            return;
        }
    }
}
